/*This file is part of WZLibCP.

 *  WZLibCP is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

 *  WZLibCP is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
    along with WZLibCP.  If not, see <http://www.gnu.org/licenses/>.
		
	Author: calc0000
*/
#include "stdafx.h"
#include "WZLibUtils.h"

using namespace std;

namespace WZLib{
	string	WZConfig::imagePath="";
	string	WZConfig::imageDir="";
};

string getFileName(string path){
	for(int i=(path.size()-1);i>=0;i--){
		if(path.at(i)=='\\' || path.at(i)=='/')
			return path.substr(i+1,path.size()-i-1);
	}
	return path;
}

string getDirName(string path){
	for(int i=(path.size()-1);i>=0;i--){
		if(path.at(i)=='\\' || path.at(i)=='/')
			return path.substr(0,i);
	}
	return ".";
}

string lower(string s){
	string ret;
	for(unsigned int i=0;i<s.size();i++){
		if(s.at(i)>=65 && s.at(i)<=90)
			ret+=(s.at(i)+32);
		else
			ret+=s.at(i);
	}
	return ret;
}

std::vector<std::string> tokenize(std::string str,std::string del,bool dropEmpty){
	std::vector<std::string> ret;
	unsigned int i=0,j=0;
	for(unsigned int l=str.size();i<l;i++){
		if(del.find(str[i])!=std::string::npos){
			std::string sub=str.substr(j,i-j);
			if(!(dropEmpty && sub.size()==0))
				ret.push_back(str.substr(j,i-j));
			j=i+1;
		}
	}
	std::string sub=str.substr(j,str.size()-j);
	if(!(dropEmpty && sub.size()==0))
		ret.push_back(str.substr(j,str.size()-j));
	return ret;
}